<include file="Public/header" />
<include file="Public/menu" />
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            供应商管理
            <small>添加供应商</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 供应商管理</a></li>
            <li class="active">添加供应商</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">添加供应商</h3>

                <div class="box-tools">

                    <div class="btn-group pull-right" style="margin-right: 10px">
                        <a href="/Qgs/supplier/index" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;供应商列表</a>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="/Qgs/supplier/add"  method="post" accept-charset="UTF-8" class="form-horizontal" pjax-container=""  id="form">

                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">供应商编码</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="code" value="" class="form-control" placeholder="供应商编码">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">供应商简称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="name" value="" class="form-control" placeholder="供应商简称">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">供应商全称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="full_name" value="" class="form-control" placeholder="供应商全称">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">负责人</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="principal" value="" class="form-control" placeholder="负责人">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">供应商地址</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="addr" value="" class="form-control" placeholder="供应商地址">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">主营类别</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="type" value="" class="form-control" placeholder="主营类别">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">联系主电话</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="phone" value="" class="form-control" placeholder="联系主电话">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">联系次电话</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="phone2" value="" class="form-control" placeholder="联系次电话">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">电子邮箱</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="email" value="" class="form-control" placeholder="电子邮箱">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <div class="col-sm-offset-2 col-sm-2">
                            <label class="col-sm-2 control-label">省</label>
                            <div class="col-sm-10">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                    <select id="province" name="province" class="form-control  select2-hidden-accessible valid" aria-invalid="false">
                                        <option value="" attr-id="">请选择</option>
                                        <foreach name="regions" item="v" >
                                            <option value="{$v.local_name}" attr-id="{$v.region_id}">{$v.local_name}</option>
                                        </foreach>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <label class="col-sm-2 control-label">市</label>
                            <div class="col-sm-10">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                    <select name="city" id="city" class="form-control  select2-hidden-accessible valid" aria-invalid="false">

                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-2">
                            <label class="col-sm-2 control-label">区</label>
                            <div class="col-sm-10">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                    <select name="region" id="region" class="form-control  select2-hidden-accessible valid" aria-invalid="false">

                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--<div class="box-body">-->
                    <!--<div class="form-group 1">-->
                        <!--<label class="col-sm-2 control-label">创建时间</label>-->
                        <!--<div class="col-sm-6">-->
                            <!--<div class="input-group">-->
                                <!--<span class="input-group-addon"><i class="fa fa-pencil"></i></span>-->
                                <!--<input class="form-control" type="text" id="create_time" name="create_time" value="" readonly />-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</div>-->
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">合同时效</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="contract_lift_time" name="contract_lift_time" value="" class="form-control" readonly>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">快递模版</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <select name="expres_template" class="form-control">
                                    <foreach name="dlytmplist" item="v" >
                                        <option value="{$v.tmp_id}" >{$v.tmpname}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-2">

                    </div>
                    <div class="col-sm-6">

                        <div class="btn-group pull-left">
                            <button type="submit" class="btn btn-info pull-right">提交</button>
                        </div>
                    </div>

                </div>
                <!-- /.box-footer -->
            </form>
        </div>

    </div></div>
    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script src="/Public/admin/jedate/jedate.js"></script>
<script>
    /*var stxt = $("#create_time").val().trim();
    if(stxt.length == 19){
        $("#create_time").val(stxt.substr(0, 16));
    }
    var start = {
        dateCell: '#create_time',
        format: 'YYYY-MM-DD hh:mm',
        minDate: '1970-01-01 00:00:00',
        festival: false,
        maxDate: '2099-12-31 23:59:59',
        isinitVal:true,
        isTime: true
    };
    jeDate(start);*/

    var contract_lift_time = $("#contract_lift_time").val().trim();
    if(contract_lift_time.length == 19){
        $("#contract_lift_time").val(contract_lift_time.substr(0, 16));
    }
    var contract_lift_time = {
        dateCell: '#contract_lift_time',
        format: 'YYYY-MM-DD hh:mm',
        minDate: '1970-01-01 00:00:00',
        festival: false,
        maxDate: '2099-12-31 23:59:59',
        isinitVal:true,
        isTime: true
    };
    jeDate(contract_lift_time);

    $("#province").change(function(){
        var region_id = $(this).find("option:selected").attr('attr-id');
        $.get("/Qgs/Supplier/get_region/grade/2/region_id/" + region_id, function(result){
            var result = eval("("+result+")");
            var html = '<option>请选择</option>';
            for (var i=0; i<result.length;i++) {
                html += '<option attr-id="'+ result[i]["region_id"] +'" value="' + result[i]["local_name"] + '">' + result[i]["local_name"] + '</option>';
            }
            $('#city').html(html);
            $('#region').html('');
        });
    });
    $("#city").change(function(){
        var region_id = $(this).find("option:selected").attr('attr-id');
        $.get("/Qgs/Supplier/get_region/grade/3/region_id/" + region_id, function(result){
            var result = eval("("+result+")");
            var html = '<option>请选择</option>';
            for (var i=0; i<result.length;i++) {
                html += '<option attr_id="'+ result[i]["region_id"] +'" value="' + result[i]["local_name"] + '">' + result[i]["local_name"] + '</option>';
            }
            $('#region').html(html);
        });
    });

    $("#form").validate({
        rules: {
            code:{
                required: true,    
                isProNumber : true        
            },
            name:{
                required: true,
                rangelength: [2, 50]
            },
            full_name:{
                required: true,
                rangelength: [2, 50]
            },
            addr:{
                required: true,
                rangelength: [2, 50]
            },
            type:{
                required: true,
                rangelength: [2, 50]
            },
            phone: {
                required: true,
                isTel: true
            },
            phone2: {            
                isTel: true
            },
            email:{
                email: true
            },
            principal:{
                required: true,
                rangelength: [2, 50]
            }
        },
        messages:{
            code: {
                required: "请输入供应商编码"
            },
            name: {
                required: "请输入供应商简称"
            },
            full_name: {
                required: "请输入供应商全称"
            },
            addr:{
                required: "请输入供应商地址"
            },
            type:{
                required: "请输入主营类别"
            },
            phone:{
                required: "请输入联系主电话"
            },
            principal:{
                required: "请输入负责人姓名"
            }
        },
        submitHandler: function(form){
            form.submit();   //提交表单
        }
    });

</script>